#include "circle.h"
#include "utilities.h"

GeometryUtilities::Circle::Circle()
  : mCenter(0.0,0.0), mRadius(0.0) {}

GeometryUtilities::Circle::Circle(const GeometryUtilities::Point &center, qreal radius)
  : mCenter(center), mRadius(radius) {}

GeometryUtilities::Circle::Circle(qreal x, qreal y, qreal radius)
  : mCenter(x,y), mRadius(radius) {}

const GeometryUtilities::Point& GeometryUtilities::Circle::center() const {return mCenter;}
qreal GeometryUtilities::Circle::radius() const {return mRadius;}

bool GeometryUtilities::Circle::isPointIn(const GeometryUtilities::Point &p) const
{
  return (p-mCenter).magnitude() < mRadius;
}

bool GeometryUtilities::Circle::isPointOn(const GeometryUtilities::Point &p) const
{
  // radius^2 = (x-center.x)^2+(y-center.y)^2
  return Utilities::floatEquality(
      mRadius*mRadius,(p.x()-mCenter.x())*(p.x()-mCenter.x())+(p.y()-mCenter.y()*p.y()-mCenter.y()), 0.01);
}
